package com.vgemv.jsutilitysdk.Reminder;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vgemv.jsutilitysdk.geometry.JsGeometryManager;
import com.vgemv.jsutilitysdk.R;

/**
 * JsReminderManager;
 */
public class JsReminderManager {

    public enum JsMessageReminderType {
        Warn(0),
        Info(1),
        Success(2),
        Error(3);

        public final int value;
        JsMessageReminderType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }


    public static View getLoadingRemindStandard1(Context context) {
        View view = (View) LayoutInflater.from(context).inflate(R.layout.gaj_loading_reminder_standard_1, null, false);
        return view;
    }


    /**
     * 根据message生成MessageView --RelativeLayout比价好.
     * @param context
     * @param message
     * @return
     */
    public static View getMessageRemindL(Context context,String message) {
        RelativeLayout fl = new RelativeLayout(context);
        String filePath  = context.getFileStreamPath("corner_rect.xml").getAbsolutePath();
        fl.setBackgroundResource(R.drawable.corner_rect);

        {
            TextView tv = new TextView(context);
            tv.setText(message);
            //设置最大宽度为屏幕一半.
            int width = JsGeometryManager.getScreenSizeInPixel(context).getWidth()/2;
            tv.setMaxWidth(width);
            fl.addView(tv);
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

            lp.addRule(RelativeLayout.CENTER_IN_PARENT);
            lp.setMargins(40,40,40,40);
            tv.setTextSize(18);
            tv.setTextColor(Color.parseColor("#ffffffff"));
            tv.setLayoutParams(lp);
        }
        return fl;
    }


    public static View getMessageReminderIl(Context context,JsMessageReminderType type,String message) {
        int drawableId = 0;
        switch (type) {
            case Info: {
                drawableId = R.mipmap.info;
                break;
            }
            case Warn: {
                drawableId = R.mipmap.warn;
                break;
            }
            case Success: {
                drawableId = R.mipmap.success;
                break;
            }
            case Error: {
                drawableId = R.mipmap.error;
                break;
            }
        }
        JsMessageReminderIl view = new JsMessageReminderIl(context);
        view.mIv.setImageResource(drawableId);
        view.mTv.setText(message);
        return view;
    }

    public static View getMessageReminderIl(Drawable drawable, String message, Context context) {

        JsMessageReminderIl view = new JsMessageReminderIl(context);
        view.mIv.setImageDrawable(drawable);

        view.mTv.setText(message);
        return view;
    }
}
